package com.sdl.timesblogmp.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sdl.timesblogmp.model.vo.ApiResult;
import com.sdl.timesblogmp.model.vo.BlogInfo;
import com.sdl.timesblogmp.model.vo.PageParam;
import com.sdl.timesblogmp.service.BlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdl
 * @since 2020-05-11
 */
@Api(value = "博客接口", tags = "博客接口")
@RestController
@RequestMapping("/blog")
public class BlogController {
    @Resource
    private BlogService blogService;
    @ApiOperation(value = "新增博客")
    @PostMapping("/post")
    public ApiResult postBlog(@RequestBody BlogInfo blogInfo) {
        System.out.println(blogInfo);
        blogService.postBlog(blogInfo);
        return ApiResult.success();
    }
    @ApiOperation(value = "获取所有博客")
    @GetMapping("/list")
    public ApiResult bloglist( PageParam pageParam) {
        IPage<BlogInfo> blogInfo = blogService.findBlogInfo(pageParam);
        return ApiResult.success(blogInfo);
    }
    @ApiOperation(value = "删除博客")
    @DeleteMapping("/del/{id}")
    public ApiResult delteOneBlog(@PathVariable Integer id){
        blogService.removeById(id);
        return ApiResult.success();
    }
    @ApiOperation(value = "获取某一篇博客")
    @GetMapping("{id}")
    public ApiResult getone(@PathVariable Integer id) {
        return ApiResult.success(blogService.findOneBlogInfo(id));
    }
    @ApiOperation(value = "获取总览信息")
    @GetMapping("getdashboardinfo")
    public ApiResult getbloginfo() {
        return ApiResult.success(blogService.getDashBoardInfo());
    }
}

